/**
 * 
 */
package com.google.code.maven.plugin.http.client.config;

import java.util.concurrent.atomic.AtomicInteger;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import com.google.code.maven.plugin.http.client.Credentials;
import com.google.code.maven.plugin.http.client.FormCredentials;

/**
 * FormCredential
 * 
 * @author Nadim Benabdenbi
 * @version 1.0
 * @since JDK1.6
 */
public class FormCredentialsConfiguration extends FormCredentials {
	
	protected static final AtomicInteger id = new AtomicInteger();	

	public FormCredentials build(DefaultListableBeanFactory factory) {
		BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FormCredentials.class);
		String beanId = Credentials.class.getSimpleName() + id.incrementAndGet();
		builder.addPropertyValue("login", getLogin() );
		builder.addPropertyValue("password", getPassword() );
		builder.addPropertyValue("parameters",getParameters());
		builder.addPropertyValue("formUrl",getFormUrl());
		builder.addPropertyValue("loginParameterName",getLoginParameterName());
		builder.addPropertyValue("passwordParameterName",getPasswordParameterName());
		factory.registerBeanDefinition(beanId, builder.getBeanDefinition());
		return factory.getBean(beanId, FormCredentials.class);
	}
}
